package cn.wsalix.finance.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.anlaser.service.impl.SimpleServiceImpl;
import cn.anlaser.utils.SearchFilter;
import cn.anlaser.utils.SearchFilter.Operator;
import cn.wsalix.finance.entity.Bank;
import cn.wsalix.finance.form.BankForm;
import cn.wsalix.finance.repository.BankRepository;
import cn.wsalix.finance.service.BankService;

@Service("bankService")
public class BankServiceImpl extends
		SimpleServiceImpl<BankForm, BankRepository, Bank>
		implements BankService {
	@Autowired
	private BankRepository bankRepository;

	@Override
	public String module() {
		return "/finance/bank";
	}

	@Override
	public BankRepository getRepository() {
		return bankRepository;
	}

	@Override
	public Class<Bank> getEntityClazz() {
		return Bank.class;
	}

	@Override
	public Map<String, SearchFilter> buildByForm(BankForm form) {
		Map<String, Object> searchParams = new HashMap<String, Object>();
		Map<String, SearchFilter> filters = SearchFilter.parse(searchParams);
		
		if (form.getName() != null && !form.getName().equals("")) {
			filters.put("name",
					new SearchFilter("nama", Operator.EQ, form.getName()));
		}
		return filters;
	}

	@Override
	public Bank add(BankForm form) {
		
		return super.add(form);
	}

	@Override
	public Bank edit(BankForm form) {
		
		return super.edit(form);
	}

}
